import 'package:enterprise_v8/generated/json/base/json_field.dart';
import 'package:enterprise_v8/generated/json/pagination.g.dart';

/// 分页模型
@JsonSerializable()
class Pagination {
  Pagination();

  factory Pagination.fromJson(Map<String, dynamic> json) =>
      $PaginationFromJson(json);

  Map<String, dynamic> toJson() => $PaginationToJson(this);

  /// 总数
  int total = 0;

  /// 每页数量，默认10
  int size = 10;

  /// 当前页，从1开始
  int current = 1;

  /// 总页数
  int get pageCount => (total / size).ceil();

  /// 是否有更多页面
  bool get hasMore => size * current < total;

  /// 判断map是否为分页结构, 根据接口响应结构来调整
  static bool isPaginationStructure(Map<dynamic,dynamic> data) {
    final bool isPagination = data.containsKey('records') && data.containsKey('total');
    return isPagination;
  }
}
